package com.ruoyi.project.report.order.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.report.order.domain.OrderReport;
import com.ruoyi.project.report.order.service.IOrderReportService;
import com.ruoyi.project.report.revenue.domain.Revenue;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/report/order")
public class OrderReportController extends BaseController {

    private String prefix = "/report/order";

    @Autowired
    private IOrderReportService orderReportService;

    @RequiresPermissions("report:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/order_report";
    }

    /**
     * 查询订单统计报表列表
     */
    @RequiresPermissions("report:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam(value = "startDate") String startDate,
                              @RequestParam(value = "endDate") String endDate)
    {
        startPage();
        List<OrderReport> list = orderReportService.selectOrderReportByDate(startDate, endDate);

        return getDataTable(list);
    }

    /**
     * 导出订单统计报表
     */
    @RequiresPermissions("report:order:export")
    @Log(title = "订单统计报表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestParam(value = "startDate") String startDate,
                             @RequestParam(value = "endDate") String endDate)
    {
        List<OrderReport> list = orderReportService.selectOrderReportByDate(startDate, endDate);
        ExcelUtil<OrderReport> util = new ExcelUtil<OrderReport>(OrderReport.class);
        return util.exportExcel(list, "订单统计报表数据");
    }
}
